package com.op.teachingliteapp.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.op.teachingliteapp.BuildConfig;
import com.op.teachingliteapp.database.table.CourseNotifTable;
import com.op.teachingliteapp.database.table.CourseTable;
import com.op.teachingliteapp.database.table.SeminarTable;
import com.op.teachingliteapp.database.table.UserTable;

/**
 * SQLiteOpenHelper
 * 
 * @author Michael
 * @date Jun 23, 2015
 */
public class MainDBHelper extends SQLiteOpenHelper {

	private static final String TAG = MainDBHelper.class.getSimpleName();

	private static final String DATABASE_NAME = "teachingliteapp.db";
	private static final int DATABASE_VERSION = 1;

	public MainDBHelper(Context context) {
		this(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	public MainDBHelper(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
		if (BuildConfig.DEBUG) {
			Log.d(TAG, "new DBHelper");
		}
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		if (BuildConfig.DEBUG) {
			Log.d(TAG, "Creating database");
		}
		UserTable.onCreate(db);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (BuildConfig.DEBUG) {
			Log.d(TAG, "Upgrading database");
		}
		UserTable.onUpgrade(db, oldVersion, newVersion);
	}

}
